package org.example;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        ArrayList<ArrayList<Integer>> re = input();

        printTwoList(re);

        printCombination(re);
    }

    private static void printCombination(ArrayList<ArrayList<Integer>> re) {
        ArrayList<Integer> first = re.get(0);
        ArrayList<Integer> second = re.get(1);

        ArrayList<Integer> result = new ArrayList<>();

        while (!first.isEmpty() && !second.isEmpty()) {
            if(first.get(0) < second.get(0)){
                result.add(first.remove(0));
            }else if(first.get(0) >= second.get(0)){
                result.add(second.remove(0));
            }
        }

        if (second.isEmpty() && !first.isEmpty()){
            int size = first.size();
            for (int i = 0; i < size; i++) {
                result.add(first.remove(0));
            }
        } else if (!second.isEmpty() && first.isEmpty()) {
            int size = second.size();
            for (int i = 0; i < size; i++) {
                result.add(second.remove(0));
                
            }
        }


        for (int i = 0; i < result.size(); i++) {
            System.out.print(result.get(i)+ " ");       //打印组合数组
        }
        System.out.println();

        int size = result.size() % 2 == 0 ?
                result.size() / 2: result.size() / 2 + 1;
        System.out.print(size + " " + result.get(size - 1));
    }

    private static void printTwoList(ArrayList<ArrayList<Integer>> re) {
        for (int i = 0; i < re.size(); i++) {
            ArrayList<Integer> print = re.get(i);
            for (int j = 0 ; j < print.size(); j++) {
                int used = print.get(j);
                System.out.print(used+ " ");

            }
            System.out.println();
        }
    }

    public static ArrayList<ArrayList<Integer>> input(){
        Scanner scanner = new Scanner(System.in);
        ArrayList<ArrayList<Integer>> result = new ArrayList<>();

        ArrayList<Integer> first = new ArrayList<>();
        ArrayList<Integer> second = new ArrayList<>();

        ArrayList<Integer> added = first;

        while(scanner.hasNextLine()){// 判断是否还有输入
            int i = Integer.parseInt(scanner.next());
            if (i == -1 && second.isEmpty()){
                added = second;
                continue;
            } else if (i == -1 && !second.isEmpty()) {
                break;
            }

            added.add(i);
        }

        result.add(first);
        result.add(second);
        scanner.close();

        return result;
    }
}